//
//  BTCCommonBuyViewController.m
//  project
//
//  Created by 张亚林 on 2017/11/5.
//  Copyright © 2017年 Macmini. All rights reserved.
//

#import "BTCCommonBuyViewController.h"

#import "UIBarButtonItem+Item.h"
#import "UIImage+TBCityIconFont.h"
#import "LWTDatePickerView.h"
@interface BTCCommonBuyViewController ()

@property (weak, nonatomic) IBOutlet UIView *fudongView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *fudongViewHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *top;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *upperViewHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeViewHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *liuyanViewTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *adressViewHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeViewTop;
@property (weak, nonatomic) IBOutlet UIView *coinView;


@property (weak, nonatomic) IBOutlet UIButton *up;
@property (weak, nonatomic) IBOutlet UIButton *down;

@property (weak, nonatomic) IBOutlet UITextField *scaleTF;
@property (weak, nonatomic) IBOutlet UITextField *danjianTF;
@property (weak, nonatomic) IBOutlet UITextField *priceUpTF;


@property (weak, nonatomic) IBOutlet UIView *timeView;
@property (nonatomic, assign)BOOL isSec;
@property (weak, nonatomic) IBOutlet UITextField *pricetf;
@property (weak, nonatomic) IBOutlet UITextField *numbertf;
@property (weak, nonatomic) IBOutlet UILabel *priceLab;
@property (weak, nonatomic) IBOutlet UILabel *priceCurrency;

@property (nonatomic, assign) NSInteger currentType;
@property (nonatomic, assign) NSInteger buyOrsell;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *adressHeight;



@end

@implementation BTCCommonBuyViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];

            UIImage *up = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e637", 25, [UIColor colorWithRed:247/255.0 green:246/255.0 blue:246/255.0 alpha:1/1.0])];
            UIImage *down =  [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e631", 25,  [UIColor colorWithRed:247/255.0 green:246/255.0 blue:246/255.0 alpha:1/1.0])];
            [self.up setBackgroundImage:up forState:UIControlStateNormal];
            [self.down setBackgroundImage:down forState:UIControlStateNormal];
    
    self.isSec = NO;
    self.fudongView.hidden = YES; //是否显示溢价
  //  self.fudongViewHeight.constant = 0;
    self.top.constant = 15;
    self.upperViewHeight.constant = 0;
    self.topViewHeight.constant = 96;
    self.adressHeight.constant = 42 + 5* 50;
    
    //判断普通买 还是 安全买
   
    [self configureTitle];
    [self resetCurrentType];
     [self isTimeView];
}


#pragma mark - 每点击一次，数值+0.01
- (IBAction)clickDown:(id)sender {
    
   // NSString *string = 0.01;
 //   self.scaleTF.text +=(NSString *)0.01;
}


- (void)resetCurrentType {
    /*
     1.普通不溢价买.
     2.普通溢价买
     3.安全不溢价买
     4.安全溢价买
     5.普通不溢价卖.
     6.普通溢价卖
     7.安全不溢价卖
     8.安全溢价卖
     
     */
    if ([self.genre isEqualToString:CoinType_Buy_NormalModel]) {
        if (self.isSec) {
            self.currentType = 1;
        } else{
            self.currentType = 2;
        }
    } else  if ([self.genre isEqualToString:CoinType_Buy_SafeModel]) {
        if (self.isSec) {
            self.currentType = 3;
        } else{
            self.currentType = 4;
        }
        
    }
//    else  if ([self.genre isEqualToString:CoinType_Sell_NormalModel]) {
//        if (self.isSec) {
//            self.currentType = 5;
//        } else{
//            self.currentType = 6;
//        }
//
//    } else  if ([self.genre isEqualToString:CoinType_Sell_SafeModel]) {
//        if (self.isSec) {
//            self.currentType = 7;
//        } else{
//            self.currentType = 8;
//        }
//
//    }
 
}

-(void)configureTitle {
    NSString *titleString =@"";
    if ([self.genre isEqualToString:CoinType_Buy_NormalModel]) {
        titleString = @"普通购买";
        [self configureLabTitle:1];
        self.buyOrsell = 1;
    } else if ([self.genre isEqualToString:CoinType_Buy_SafeModel]){
        titleString = @"安全购买";
        self.buyOrsell = 1;
        [self configureLabTitle:1];
    } else if ([self.genre isEqualToString:CoinType_Sell_NormalModel]) {
       titleString = @"普通出售";
        [self configureLabTitle:2];
        self.buyOrsell = 2;
    }else {
       titleString = @"安全出售";
        self.buyOrsell = 2;
        [self configureLabTitle:2];
        
    }
    
//    if ([self isNoraml]) {
//
//    }
    
    self.navigationItem.title = titleString;
    
}


- (void)configureLabTitle:(NSInteger)type {
    
    //1. 买 2.卖.
    if (type == 1) {
        self.pricetf.placeholder = @"买入金额";
        self.numbertf.placeholder = @"买入数量";
        self.priceLab.text = @"买入量";
        self.priceCurrency.text = @"BTC";
    } else{
        self.pricetf.placeholder = @"卖出金额";
        self.numbertf.placeholder = @"买入数量";
        self.priceLab.text = @"卖出量";
        self.priceCurrency.text = @"BTC";
    }
    
   
    
}
- (BOOL)isNoraml {
    if ([self.genre isEqualToString:CoinType_Sell_NormalModel] || [self.genre isEqualToString:CoinType_Buy_NormalModel]) {
        return YES;
    } else{
        return NO;
    }
    
    
}
- (void)isTimeView {
    
    //normal
    if ([self isNoraml]) {
        self.adressHeight.constant = -10;
        self.coinView.hidden=YES;
        self.timeViewTop.constant = 0;
    } else {
       self.adressHeight.constant = 64;
        self.timeViewTop.constant = 64;
    }
    
}

- (IBAction)datePickShow:(UIButton *)sender {
    
    LWTDatePickerView *pickerView = [[LWTDatePickerView alloc] initWithPickerViewWithCenterTitle:@"广告仅在开放时间可被人看见" LimitMaxIndex:50];
    
//    [pickerView pickerViewDidSelectRowWithLeftIndex:_minIndex andRightIndex:_maxIndex];
    
    [pickerView pickerVIewClickCancelBtnBlock:^{
        
        NSLog(@"取消");
        
    } sureBtClcik:^(NSInteger leftIndex, NSInteger rightIndex, NSString *leftAndRightString) {
        
//        _dateLabel.text = leftAndRightString;
//        _minIndex = leftIndex;
//        _maxIndex = rightIndex;
        
        [sender setTitle:leftAndRightString forState:0];
        //
    }];
    
}

- (IBAction)clickFudong:(id)sender {
    
    if (self.isSec == NO) {
        
      self.fudongView.hidden = NO;
    //    self.fudongViewHeight.constant = 44;
        self.top.constant = 60;
        self.upperViewHeight.constant = 44;
        self.topViewHeight.constant = 180;
        
        self.isSec = YES;
        

        
    } else {
        self.fudongView.hidden = YES;
  //      self.fudongViewHeight.constant = 0;
        self.top.constant = 15;
        self.topViewHeight.constant = 96;
        
        self.isSec = NO;
    }
}
- (IBAction)saveAds:(UIButton *)sender {
    [self.view endEditing:YES];
    NSMutableDictionary *para = @{}.mutableCopy;
    para[@"currency"] = @"1"; //币种;
    if (self.buyOrsell ==1) {
       para[@"isSale"] = @"false"; //买
    } else{
       para[@"isSale"] = @"true"; //卖
    }
    
    if ( [self isNoraml]) {
        para[@"isSafe"] = @"false"; //普通
    } else{
        para[@"isSafe"] = @"true"; //安全模式
      
    }
    
    if ( self.isSec ) {
        //不溢价模式
        para[@"isFixed"] = @"true";
    } else{
        para[@"isFixed"] = @"false";
         para[@"floatPercent"] = @"false";
        if (self.buyOrsell == 1) {
                 para[@"ceil"] = @"1";
        } else{
            para[@"floor"] = @"2";
        }
    }
    
    
    para[@"price"] = @"1";  //价格..
    para[@"quantity"] = @"1"; //数量
    para[@"remark"] = @"1"; //备注信息;
    para[@"startTime"] = @"1"; //币种;
    para[@"threshold"] = @"1"; //币种;
    para[@"collectionCoinAddr"] = @"1"; //币种;
    
    [adshttps saveAdds:para sucessBlock:^(id jsonResponse) {
        
    } Error:^(id jsonResponse) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
